package com.yidu.qianfeng.controller;

import com.yidu.qianfeng.common.bean.client.Consignee;
import com.yidu.qianfeng.common.bean.client.Shipper;
import com.yidu.qianfeng.service.impl.ChientServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户模块
 */
@Controller("chientController")
public class ChientController {
    /*加载发货方*/
    @RequestMapping("/goShipper")
    public String goShipper(){
        return "views/shippper";
    }
    /*加载收货方*/
    @RequestMapping("/goConsignee")
    public String goConsignee(){
        return "views/consignee";
    }

    @Resource(name = "chientServiceImpl")//依赖注入服务层
    private ChientServiceImpl chientService;

    /**
     * 分页查询发货方表
     * @param page 页面
     * @param limit 页目
     * @return map集合
     */
    @RequestMapping("/selectShipperPaing")
    public @ResponseBody Map selectShipperPaing(int page,int limit){
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        //查询总条目数
        int count = chientService.selectShipperCount();
        //count放入map集合中
        map.put("count",count);
        //计算偏移量
        int offset = (page-1)*limit;
        //查询发货方Shipper列表
        List<Shipper> shippers = chientService.selectShipperPaing(offset,limit);
        //放入map集合中
        map.put("data",shippers);

        return map;
    }

    /**
     * 发货单位模糊查询
     * @param shipperCom 发货单位
     * @return 结果对象
     */
    @RequestMapping("/likeSelectShipperCom")
    public @ResponseBody Map likeSelectShipperCom(String shipperCom){
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        //查询总条目数
        int count = chientService.likeSelectShipperCom(shipperCom).size();
        //count放入map集合中
        map.put("count",count);
        //模糊查询shipper集合
        List<Shipper> shippers = chientService.likeSelectShipperCom(shipperCom);
        //放入map集合中
        map.put("data",shippers);
        return map;
    }

    /**
     * 新增发货方
     * @param shipper 发货方对象
     * @return 结果信息
     */
    @RequestMapping("/insertShipper")
    public @ResponseBody String insertShipper(Shipper shipper){
        System.out.println(shipper.toString());

        return chientService.insertShipper(shipper);
    }

    /**
     * 删除发货方数据
     * @param shipperId 主键id
     * @return 结果信息
     */
    @RequestMapping("/deleteShipper")
    public @ResponseBody String deleteShipper(String shipperId){

        return chientService.deleteShipper(shipperId);
    }

    /**
     * 根据id查询发货方数据
     * @param shipperId 主键id
     * @return 结果对象
     */
    @RequestMapping("/byIdQueryShipper")
    public @ResponseBody Shipper byIdQueryShipper(String shipperId){

        return chientService.byIdQueryShipper(shipperId);
    }

    /**
     * 修改发货方数据
     * @param shipper 发货方对象
     * @return 结果信息
     */
    @RequestMapping("/updateShipper")
    public @ResponseBody String updateShipper(Shipper shipper){

        return chientService.updateShipper(shipper);
    }

    /**
     * 分页查询收货方表
     * @param page 页面
     * @param limit 页目
     * @return map集合
     */
    @RequestMapping("/selectConsiPaing")
    public @ResponseBody Map selectConsiPaing(int page,int limit){
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        //查询总条目数count
        int count = chientService.selectConsiCount();
        map.put("count",count);
        //计算偏移量
        int offset = (page-1)*limit;
        //查询consignee顾客列表
        List<Consignee> consigneeList = chientService.selectConsiPaing(offset,limit);
        //放入map集合中
        map.put("data",consigneeList);

        return map;
    }

    /**
     * 收货单位模糊查询
     * @param consiCom 收货单位
     * @return 结果对象
     */
    @RequestMapping("/likeSelectConsiCom")
    public @ResponseBody Map likeSelectConsiCom(String consiCom){
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        //查询总条目数count
        int count = chientService.likeSelectConsiCom(consiCom).size();
        //count放入map集合中
        map.put("count", count);
        //模糊查询用户列表
        List<Consignee> consigneeList = chientService.likeSelectConsiCom(consiCom);
        //放入map集合中
        map.put("data",consigneeList);
        return map;
    }

    /**
     * 新增收货方
     * @param consignee 收货方对象
     * @return 结果信息
     */
    @RequestMapping("/insertConsi")
    public @ResponseBody String insertConsi(Consignee consignee){

        return chientService.insertConsi(consignee);
    }

    /**
     * 删除收货方数据
     * @param consiId 主键id
     * @return 结果信息
     */
    @RequestMapping("/deleteConsi")
    public @ResponseBody String deleteConsi(String consiId){

        return chientService.deleteConsi(consiId);
    }

    /**
     * 根据id查询收货方数据
     * @param consiId 主键id
     * @return 结果对象
     */
    @RequestMapping("/byIdQueryConsi")
    public @ResponseBody Consignee byIdQueryConsi(String consiId){

        return chientService.byIdQueryConsi(consiId);
    }

    /**
     * 修改收货方数据
     * @param consignee 收货方对象
     * @return 结果信息
     */
    @RequestMapping("/updateConsi")
    public @ResponseBody String updateConsi(Consignee consignee){

        return chientService.updateConsi(consignee);
    }

}
